﻿@{
    ViewBag.Title = "房型管理";
}
@section header
{
    <style type="text/css">
    </style>
}
<table id="dg" title="房型名称" class="easyui-datagrid"
    url="/roomtype/get"
    toolbar="#toolbar" pagination="false"
    rownumbers="true" fitcolumns="true" singleselect="false" ctrlselect="true" striped="true">
    <thead>
        <tr>
            <th field="name">房型名称</th>
            <th field="singlePrice">每日房单价</th>
            <th field="minFeeForHourRoom">钟点房最低消费</th>
            <th field="pricePerHour">钟点房每小时费用</th>
        </tr>
    </thead>
</table>

<div id="toolbar">
    <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-add" plain="true" onclick="newAdd()">新增</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-edit" plain="true" onclick="edit()">编辑</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-remove" plain="true" onclick="destory()">删除</a>
</div>

<div id="dlg" class="easyui-dialog" style="width: 440px; height: 260px; padding: 10px 20px"
    closed="true" buttons="#dlg-buttons">
    <form id="fm" method="post" data-options="novalidate:true">
        <input type="hidden" name="roomTypeId" />
        <div class="fitem">
            <label>房型名称:</label>
            <input name="name" class="easyui-textbox" required="true" />
        </div>
        <div class="fitem">
            <label>每日房单价:</label>
            <input name="singlePrice" class="easyui-textbox" required="true" />
        </div>
        <div class="fitem">
            <label>钟点房最低消费:</label>
            <input name="minFeeForHourRoom" class="easyui-textbox" required="true" />
        </div>
        <div class="fitem">
            <label>钟点房每小时费用:</label>
            <input name="pricePerHour" class="easyui-textbox" required="true" />
        </div>
    </form>
</div>

<div id="dlg-buttons">
    <a href="javascript:void(0)" class="easyui-linkbutton c6" iconcls="icon-ok" onclick="save()" style="width: 90px">保存</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')" style="width: 90px">取消</a>
</div>
@section Scripts
{
    <script type="text/javascript">
        var msgTitle = "房型管理";
        function newAdd() {
            $('#dlg').dialog('open').dialog('setTitle', '新增房型');
            $('#fm').form('clear');
        }
        function save() {
            if (!$('#fm').form('enableValidation').form('validate')) {
                return;
            }
            $.post('/roomtype/save',
                     $('#fm').serialize(),
                      function (data) {
                          var msg = '';
                          if (data.msg.length != 0) {
                              $.each(data.msg, function () {
                                  msg = data.msg + msg + '<br/>';
                              });
                              $.messager.alert(msgTitle, msg, 'error');

                          }
                          else {
                              $.messager.alert(msgTitle, '提交成功！', 'info');
                              $('#dlg').dialog('close'); // close the dialog
                              $('#dg').datagrid('reload'); // reload the user data
                          }
                      });
        }

        function edit() {
            var rows = $('#dg').datagrid('getSelections');
            if (rows.count > 1)
                $.messager.alert(msgTitle, '请选择一条数据编辑！', 'info');
            var row = $('#dg').datagrid('getSelected');
            if (row) {
                $('#dlg').dialog('open').dialog('setTitle', '编辑房型');
                $('#fm').form('load', row);
                $('#fm input[name=name]').prev().focus();//设置焦点
            }
        }

        function destory() {
            var row = $('#dg').datagrid('getSelections');
            if (row.length > 0) {
                $.messager.confirm('Confirm', '确实要删除吗?', function (r) {
                    if (r) {
                        $.post('/roomtype/remove',
                              JSON.stringify(row),
                              function (data) {
                                  var msg = '';
                                  if (data.msg.length != 0) {
                                      $.each(data.msg, function (index, item) {
                                          msg = msg + item + '<br/>';
                                      });
                                      $.messager.alert(msgTitle, msg, 'error');
                                  }
                                  else {
                                      $.messager.alert(msgTitle, '提交成功！', 'info');
                                      $('#dlg').dialog('close'); // close the dialog
                                      $('#dg').datagrid('reload'); // reload the user data
                                  }
                              });
                    }
                });
            }
        }
    </script>
}
